<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<style type="text/css">
    .equipment_factory_listbtn{
        float:right;
        color:#38adff;
        font-size:15px;
        display:inline-block;
        margin-right:25px;
    }
    .equipment_factory_listbtn1, .equipment_factory_listbtn2{
        width:70px;
        height:32px;
        line-height:32px;
        text-align:center;
        text-indent:0;
        background:#38adff;
        display:inline-block;
        color:#fff;
        border-radius:3px;
        font-size:15px;
    }
    .equipment_factory_listbtn2{
        margin-left:20px;
        background:#CCC;
    }
</style>

<div class="page_right equipmentpage_right">
    <div class="equipment_rightp" style="${deviceTypeName!=null?'':'display: none'}" >
        <span class="equipment_rightp_text1">${deviceTypeName}</span>
        <!-- fixme s -->
        <a class="equipment_factory_listbtn" href="javascript:;">修改类型名称</a>
        <div class="equipement_factory_details_editdv" name="0">
            <input type="text" class="equipement_factory_details_editval" placeholder="请输入类型名称">
            <a href="javascript:;" class="equipment_factory_listbtn1">确认</a>
            <a href="javascript:;" class="equipment_factory_listbtn2">取消</a>
        </div>
        <!-- fixme e -->
    </div>
    <ul class="equipment_rightTitle">
        <li>序号</li>
        <li>设备名称</li>
        <li>设备简码</li>
        <li>IMEI/MAC码</li>
        <li>场地名称</li>
        <li>信号强度</li>
        <li>在线状态</li>
        <li>设备状态</li>
        <li>用户名</li>
        <li>操作</li>
    </ul>
    <div class="equipment_rightContentdv">
        <c:forEach items="${scrollResult.rows}" var="data" varStatus="status">
        <ul class="equipment_rightContent">
            <li>${status.count}</li>
            <li>${data.deviceName}</li>
            <li>${data.shortCode}</li>
            <li>${data.imei}</li>
            <li>${data.placeName}</li>
            <c:choose>
                <c:when test="${data.signalStrength<2}">
                    <li class='equipment_signal cur3'>无信号</li>
                </c:when>
                <c:when test="${data.signalStrength<=7}">
                    <li class='equipment_signal cur2'>弱</li>
                </c:when>
                <c:when test="${data.signalStrength<=14}">
                    <li class='equipment_signal cur1'>微弱</li>
                </c:when>
                <c:when test="${data.signalStrength<=23}">
                    <li class='equipment_signal cur1'>中</li>
                </c:when>
                <c:otherwise>
                    <li class='equipment_signal'>强</li>
                </c:otherwise>
            </c:choose>
            <li class='equipment_state ${data.isOnLine==1?"":"cur"}'>${data.isOnLine==1?"在线":"离线"}</li>
            <li class='equipment_enable ${data.state==1?"":"cur"}'>${data.state==1?"启用":"禁用"}</li>
            <li>${data.userName}</li>
            <li>
                <a class="equipment_disable ${data.state==1?"":"cur"}" href="javascript:;" onclick="changeDeviceState(${data.deviceId},${status.index})">${data.state==1?"禁用":"启用"}</a>
                <a class="equipment_edit" href="javascript:;" onclick="showParamView(${data.deviceId})">编辑</a>
            </li>
        </ul>
        </c:forEach>
    </div>
    <div class="equipment_page" style="${scrollResult.total>0?"":"display:none"}"><div class="page_dv"></div></div>

</div>
<div class="page_line"></div>
<link rel="stylesheet" href="${basePath}resources/css/v2/factory/paging.css">
<script language="javascript" src="${basePath}resources/js/v2/factory/paging.js"></script>
<script type="application/javascript">
    var total = '${scrollResult.total}';
    var temp=Math.ceil(total/10);
    var typeName = '${deviceType}';

    $(".equipment_page").paging({
        "container":".equipment_page",
        "indexmax":temp,
        "indexcur":1,
        "flag":true,
        "clickevent":function(flag, indexcur){
            if(flag){
                $.ajax({
                    url: uri+"getPagDevice",
                    type: 'POST',
                    data: {"typeName":typeName,"page":indexcur},
                    error: function (response) {
                        $errorMsg(response);
                    },
                    success: function (ret) {
                        if(ret.result==true){
                            doDeviceList(ret.scrollResult);
                        }else{
                            alert(ret.info);
                        }
                    }
                });
            }
        },
    });

    function doDeviceList(objVal) {
        if(objVal.total>0){
            $(".equipment_rightContentdv").empty();
            for(var index in objVal.rows){
                var equipment_allLi="";
                for(var j=0; j<10; j++) {
                    if (j == 0) {
                        equipment_allLi += "<li>" + eval(index+"+"+1)+ "</li>";
                    } else if (j == 1) {
                        equipment_allLi += "<li>" + objVal.rows[index]["deviceName"] + "</li>";

                    } else if (j == 2) {
                        equipment_allLi += "<li>" + objVal.rows[index]["shortCode"] + "</li>";

                    } else if (j == 3) {
                        equipment_allLi += "<li>" + objVal.rows[index]["imei"] + "</li>";

                    } else if (j == 4) {
                        equipment_allLi += "<li>" + objVal.rows[index]["placeName"] + "</li>";

                    } else if (j == 5) {
                        if (objVal.rows[index]["signalStrength"] < 2) {
                            equipment_allLi += "<li class='equipment_signal cur3'>无信号</li>";
                        }else if (objVal.rows[index]["signalStrength"] <= 7) {
                            equipment_allLi += "<li class='equipment_signal cur2'>弱</li>";
                        }else if (objVal.rows[index]["signalStrength"] <= 14) {
                            equipment_allLi += "<li class='equipment_signal cur1'>微弱</li>";
                        } else if (objVal.rows[index]["signalStrength"] <= 23) {
                            equipment_allLi += "<li class='equipment_signal cur1'>中</li>";
                        } else {
                            equipment_allLi += "<li class='equipment_signal'>强</li>";
                        }
                    } else if (j == 6) {
                        if(objVal.rows[index]["isOnLine"]==1){
                            equipment_allLi += "<li class='equipment_state'>在线</li>";
                        }else {
                            equipment_allLi += "<li class='equipment_state cur'>离线</li>";
                        }
                    } else if (j == 7) {
                        if(objVal.rows[index]["state"]==1){
                            equipment_allLi += "<li class='equipment_enable'>启用</li>";
                        }else {
                            equipment_allLi += "<li class='equipment_enable cur'>禁用</li>";
                        }
                    } else if (j == 8) {
                        equipment_allLi += "<li>" + objVal.rows[index]["userName"] + "</li>";
                    } else if (j == 9) {
                        if(objVal.rows[index]["state"]==1){
                            equipment_allLi += "<li><a class='equipment_disable' onclick='changeDeviceState("+objVal.rows[index]["deviceId"]+","+index+")' name='"+objVal.rows[index]["deviceId"]+"' href='javascript:;'>禁用";
                        }else {
                            equipment_allLi += "<li><a class='equipment_disable cur' onclick='changeDeviceState("+objVal.rows[index]["deviceId"]+","+index+")' name='"+objVal.rows[index]["deviceId"]+"' href='javascript:;'>启用";
                        }
                        equipment_allLi += "</a><a class='equipment_edit' href='javascript:;' onclick='showParamView("+objVal.rows[index]["deviceId"]+")'>编辑</a></li>";
                    }
                }
                $(".equipment_rightContentdv").append("<ul class='equipment_rightContent'>"+equipment_allLi+"</ul>");
            }
        }
    }

    function changeDeviceState(device,index){
        var stateName ="";
        if($(".equipment_rightContentdv .equipment_disable:eq("+index+")").text()=="启用"){
            stateName = 2;
        }else{
            stateName = 1;
        }
        $.ajax({
            url: uri+"updateDeviceState",
            type: 'POST',
            data: {"deviceVal":device,"stateName":stateName},
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if(ret.result==true){
                    if($(".equipment_rightContentdv .equipment_disable:eq("+index+")").text()=="启用"){
                        $(".equipment_rightContentdv .equipment_disable:eq("+index+")").text("禁用").removeClass("cur");
                        $(".equipment_rightContentdv .equipment_enable:eq("+index+")").text("启用").removeClass("cur");
                        alert("操作成功，该设备已启用", "cur");
                    }else{
                        $(".equipment_rightContentdv .equipment_disable:eq("+index+")").text("启用").addClass("cur");
                        $(".equipment_rightContentdv .equipment_enable:eq("+index+")").text("禁用").addClass("cur");
                        alert("操作成功，该设备已禁用", "cur");
                    }
                }else{
                    alert(ret.info);
                }
            }
        });
    }

    function showParamView(device){
        window.location.href = uri+typeName+"/showParamView/"+device;
    }

    //修改参数组名称  显示
    $(".equipment_factory_listbtn").on("click", function(){
        var equipment_factory_index=$(this).closest("div").find(".equipement_factory_details_editdv").attr("name");
        var equipment_rightp_text1=$(".equipment_rightp_text1").text();
        $(".equipement_factory_details_editdv[name="+equipment_factory_index+"] .equipement_factory_details_editval").val(equipment_rightp_text1);
        $(".equipement_factory_details_editdv[name="+equipment_factory_index+"]").css({"transition":"all 0.2s", "left":"0","opacity":"1"});
    })
    //修改参数组名称  取消
    $(".equipment_factory_listbtn2").on("click", function() {
        var equipment_factory_index = $(this).closest("div").attr("name");
        $(".equipement_factory_details_editdv[name=" + equipment_factory_index + "]").css({
            "transition": "all 0.2s",
            "left": "950px",
            "opacity": "0"
        });
    })
    //修改参数组名称  确认
    $(".equipment_factory_listbtn1").on("click", function(){
        var equipment_factory_index=$(this).closest("div").attr("name");
        var equipment_rightp_text1=$(".equipment_rightp_text1").text();
        var equipement_factory_details_editval=$(".equipement_factory_details_editdv[name="+equipment_factory_index+"] .equipement_factory_details_editval").val();
        var deviceType = "${deviceType}";
        $.ajax({
            url: "${basePath}v2/factory/device/updateDeviceType",
            type: 'POST',
            data: {"deviceType":deviceType,"deviceTypeName":equipement_factory_details_editval},
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                if(ret.result==true){
                    //重新赋值
                    $(".equipment_rightp_text1").text(equipement_factory_details_editval);
                    $(".equipment_parameter .equipment_parMorebtn").each(function(index){
                        if($(".equipment_typeMore a:eq("+index+")").text()==equipment_rightp_text1){
                            $(".equipment_typeMore a:eq("+index+")").text(equipement_factory_details_editval);
                            $(".equipment_parameter .equipment_parMorebtn:eq("+index+")").text(equipement_factory_details_editval);
                            $(".equipement_factory_details_editdv[name="+equipment_factory_index+"]").css({"transition":"all 0.2s", "left":"950px","opacity":"0"});
                        }
                    })
                }else{
                    alert(ret.info);
                }
            }
        });
    });
</script>